{* Модуль добавления услуги *}

<script type="text/javascript">
<!--{literal}
$(document).ready
(
    function()
    {
		$('div.dialog#service').dialog
		(
		    'option',
		    {
			title:	'Добавить услугу',
			position: [350,100],
			width:	860,
			resizable:	false,
			buttons:
			{
			    'Сохранить':	function(){$(this).find('form').submit();}
			}
		    }
		);

		$( "div.tabs#service-add-tabs" ).tabs
		(
			'option',
			{
				collapsible: true,
				selected: 0
			}
		);


	$('a#service-add').click(function(){$('div.dialog#service').dialog('open');});

	$('a#password-generate').click(function(){$.getJSON('json/getRandomPassword.php',function(json){$('input#password').val(json['pw']);});});

	$('select#service-name-id').change
	(
	    function()
	    {
			$('.service-options:visible').hide();

			switch( $(this).val() )
			{
				//voice
			    case '3':
					$('.service-options#service-name-3').show();
					break;
				//voip
				case '30':
					$('.service-options#service-name-30').show();
					break;
			}
	    }
	);


	$('form#service-add')
//	    .find('input:submit')
	    .submit
	    (
		function()
		{
		    $.getJSON
		    (
			'check-number.php',
			{ num: $('input:text#phone-number').val() },
			function(json)
			{
			    if ( json['r']=='BUSY' )
			    {
				alert('Указанный номер занят другим абонентом!');
				$('input:text#phone-number').select();
				return false;
			    }
			    else
			    {
				ok = true;
				$('form#service-add').submit();
			    }
			}
		    );

		    if ( !ok ) { return false; }
		}
	    );

	    $(function() 
	    {
			$( "#phone-number-voip" ).autocomplete
			({
				source:	'json/getDictionary.php'
				+ '?dictionary=searchphonenumbers'
			});
		});

		$(function() 
	    {
			$( "#phone-number-voip-main" ).autocomplete
			({
				source:	'json/getDictionary.php'
				+ '?dictionary=searchphonenumbersmain'
			});
		});

		$(function() 
	    {
			$( "#device-sn" ).autocomplete
			({
				source:	'json/getDictionary.php'
				+ '?dictionary=searchdevicesn'
			});
		});
    }
);


{/literal}-->
</script>

<!-- Добавление услуги -->
<div class="dialog" id="service">
    <form action="db.php" method="post" id="service-add">
	<input type="hidden" name="action" value="service.new.do"/>
	<input type="hidden" name="account_id" value="{$customer.account_id}"/>

	<table class="ui-widget" cellspacing="0" width="100%">
		<tr>
			<td align="right">Услуга:</td>
			<td>
			    <select name="service_name" id="service-name-id">
			    {foreach from=$service_names item=sn}
					<option value="{$sn.id}">{$sn.service_name}</option>
			    {foreachelse}
					<option class="ui-state-disabled" value="">Нет доступных услуг</option>
			    {/foreach}
			    </select>
			</td>
	    </tr>
	</table>

		<div class="tabs" id="service-add-tabs">
		    <ul>
			<li><a href="#service-main">Основное</a></li>
			<li><a href="#service-additional">Дополнительное</a></li>
		    </ul>

		    <div id="service-main">
				<table class="ui-widget" cellspacing="0" width="100%">
				    <tr>
					<td align="right">Исполнитель:</td>
					<td>
					    <select name="executive">
					    {foreach from=$executives item=executive}
						<option value="{$executive.id}">{$executive.executive_name}</option>
					    {foreachelse}
						<option class="ui-state-disabled" value="">Нет доступных исполнителей</option>
					    {/foreach}
					    </select>
					</td>
				    </tr>
				    <tr>
					<td align="right">Договор:</td>
					<td>
					    <select name="contract_id">
					    {foreach from=$contract_numbers item=contract_number}
						<option value="{$contract_number.id}">{$contract_number.contract_number}</option>
					    {foreachelse}
						<option class="ui-state-disabled" value=NULL>Нет договоров</option>
					    {/foreach}
					    </select>
					</td>
				    </tr>
				    <tr>
					<td align="right">Количество:</td>
					<td><input type="text" name="quantity" value="1"/></td>
				    </tr>
				    <tr>
					<td align="right">Стоимость:<br/><small>(за 1 шт.)</td>
					<td><input type="text" name="cost" value="0.00"/></td>
				    </tr>
				    <tr>
					<td align="right">Ежемесячная:</td>
					<td><input type="checkbox" name="monthly"/></td>
				    </tr>
				    <tr>
					<td align="right">Начало:</td>
					<td><input type="text" name="start_date" class="date"/></td>
				    </tr>
				    <tr>
					<td align="right">Конец:</td>
					<td><input type="text" name="stop_date" class="date"/></td>
				    </tr>
				    <tr>
				    <td align="right">Выставлять счет ежемесячно</td>
					<td><input type="text" name="date_of_invoice" value="31"/></td> 
					<td align="left">введите 31 - если хотите указать конец месяца</td>
				    </tr>
				    <tr>
				    <td align="right">Отсрочка платежа</td>
					<td><input type="text" name="payment_delay" value="0"/></td>
				    </tr>
				</table>
	    	</div>
	    	<div id="service-additional">
	    		<!--voice-->
	    		<table class="service-options ui-state-default" id="service-name-3" style="display:none;">
					<tr>
					    <td align="right"><strong>Номер телефона:</strong></td>
					    <td><input type="text" name="phone_number" id="phone-number-search"/></td>
					</tr>
					<tr>
					    <td align="right"><strong>Тариф:</strong></td>
					    <td>
						<select name="phone_rate_id">
						{foreach from=$phone_rates item=rate}
						    <option value="{$rate.id}">{$rate.rate_name}</option>
						{/foreach}
						</select>
					    </td>
					</tr>
				</table>
				<!--voip-->
				<table class="service-options ui-state-default" id="service-name-30" style="display:none;">
					<tr>
					   <td align="right"><strong>Номер телефона:</strong></td>
					   <td>
						   <div class="ui-widget">
								<input id="phone-number-voip" name="phone_number_voip">
							</div>
						</td>
					</tr>
					<tr>
					    <td align="right"><strong>Тариф:</strong></td>
					    <td>
						<select name="phone_rate_id">
						{foreach from=$phone_rates item=rate}
						    <option value="{$rate.id}">{$rate.rate_name}</option>
						{/foreach}
						</select>
					    </td>
					</tr>
					<tr>
				    	<td align="right">Количество каналов</td>
						<td><input type="text" name="number_of_channel" value="1"/></td>
				    </tr>
				    <tr>
				    	<td align="right">Пароль:</td>
					    <td>
							<input type="text" name="voip_service_password" id="password"/>
							<a href="javascript:void(0)" id="password-generate"><img src="images/icons/key_16.png" border="0" title="Сгенерировать пароль"/></a>
					    </td>
				    </tr>
				    <tr>
				    	<td align="center" colspan=2>Доступ к видам связи</td>
				    	<td align="center" colspan=2>Характеристики</td>
				    </tr>
				    <tr>
						<td align="right">Местная связь:</td>
						<td>
						    <select name="city_uplink_id" id="city-uplink-id">
						    {foreach from=$city_uplinks item=su}
							<option value="NULL">запрещено</option>
							<option value="{$su.id}">{$su.name}</option>
						    {foreachelse}
							<option class="ui-state-disabled" value="">Нет доступных услуг</option>
						    {/foreach}
						    </select>
						</td>
						<td align="right">Владелец оборцдования:</td>
						<td>
						    <select name="device_own" id="device-own">
							<option value="operator">Оператор</option>
							<option value="customer">Клиент</option>
						    </select>
						</td>
				    </tr>
				    <tr>
						<td align="right">Зона мобильные:</td>
						<td>
						    <select name="zona_mobile_uplink_id" id="zona-mobile-uplink-id">
						    {foreach from=$zona_mobile_uplinks item=zmu}
							<option value="NULL">запрещено</option>
							<option value="{$zmu.id}">{$zmu.name}</option>
						    {foreachelse}
							<option class="ui-state-disabled" value="">Нет доступных услуг</option>
						    {/foreach}
						    </select>
						</td>
						<td align="right">Серийный номер:</td>
						<td>
						   <div class="ui-widget">
								<input id="device-sn" name="SN">
							</div>
						</td>
				    </tr>
				    <tr>
						<td align="right">Зона стационарные:</td>
						<td>
						    <select name="zona_stationary_uplink_id" id="zona-stationary-uplink-id">
						    {foreach from=$zona_stationary_uplinks item=zsu}
							<option value="NULL">запрещено</option>
							<option value="{$zsu.id}">{$zsu.name}</option>
						    {foreachelse}
							<option class="ui-state-disabled" value="">Нет доступных услуг</option>
						    {/foreach}
						    </select>
						</td>
						<td align="right">Модель оборудования:</td>
						<td><input type="text" name="device_model" id="device-model"/></td>
				    </tr>
				    <tr>
						<td align="right">Междугородние:</td>
						<td>
						    <select name="long_distance_uplink_id" id="long-distance-uplink-id">
						    {foreach from=$long_distance_uplinks item=ldu}
							<option value="NULL">запрещено</option>
							<option value="{$ldu.id}">{$ldu.name}</option>
						    {foreachelse}
							<option class="ui-state-disabled" value="">Нет доступных услуг</option>
						    {/foreach}
						    </select>
						</td>
						<td align="right">логин от оборудования</td> 
						<td><input type="text" name="device_login" id="device-login"/></td>
				    </tr>
				    <tr>
						<td align="right">Международные:</td>
						<td>
						    <select name="international_uplink_id" id="international-uplink-id">
						    {foreach from=$international_uplinks item=iu}
							<option value="NULL">запрещено</option>
							<option value="{$iu.id}">{$iu.name}</option>
						    {foreachelse}
							<option class="ui-state-disabled" value="">Нет доступных услуг</option>
						    {/foreach}
						    </select>
						</td>
						<td align="right">пароль от оборудования</td> 
						<td><input type="text" name="device_password" id="device-password"/></td>
				    </tr>
				    <tr>
						<td></td>
						<td></td>
						<td align="right">Порт</td> 
						<td><input type="text" name="phone_port" value="0"/></td>
				    </tr>
				    <tr>
					   <td align="right"><strong>Многоканальный телефон:</strong></td>
					   <td>
						   <div class="ui-widget">
								<input id="phone-number-voip-main" name="phone_number_voip_multiline">
							</div>
						</td>
					</tr>

				</table>
	    	</div>
	    </div>
    </form>
</div>
